/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package helloplash;

import plash.display.Sprite;
import plash.display.Stage;
import plash.events.Event;
import plash.events.IEventListener;
import plash.events.MouseEvent;
import plash.geom.Rectangle;
import plash.text.TextField;
import plash.utils.Logger;

/**
 *
 * @author User
 */
public class MyStage extends Stage implements IEventListener
{
    Sprite test;
//    TextField tf;
    
    public MyStage()
    {
        super(new Rectangle(0, 0, 500, 500), 0xFFFFFF);
        _init();
    }

    private void _init()
    {
        test = new Sprite();
//        tf = new TextField();
        
        test.getGraphics().clear();
        test.getGraphics().setLineStyle(5, 0x000000, 1.0f);
        test.getGraphics().beginFill(0xCC00CC, 1.0f);
        test.getGraphics().drawRectangle(0,0,50,50);
        test.getGraphics().endFill();
        
        test.setDoubleClickEnabled(true);
        
//        tf.setX(200);
//        tf.setWordWrap(true);
//        tf.setY(200);
//        tf.setBorder(true);
//        tf.setText("Hello Plash!Hello Plash!Hello Plash!Hello Plash!");
        
        addChild(test);
//        addChild(tf);
        
        test.addEventListener(MouseEvent.CLICK, this);
        test.addEventListener(MouseEvent.DOUBLE_CLICK, this);
        test.addEventListener(Event.ENTER_FRAME, this);
    }

    @Override
    public void event(Event e)
    {        
        if(e.name.equals(Event.ENTER_FRAME))
        {
//            tf.setRotation(tf.getRotation() + 1);
            test.setX(test.getX() + 1);
        }
        else if(e.name.equals(MouseEvent.DOUBLE_CLICK))
        {
            Logger.log("MOUSE DOUBLE CLICK DETECTED FOR "+e.target);
        }
        else if(e.name.equals(MouseEvent.CLICK))
        {
            Logger.log("MOUSE CLICK DETECTED FOR "+e.target);
        }
    }
}
